{template header}
<link rel="stylesheet" href="static/calendar/js/calendar.css" />
<style type="text/css">
  .bannerDiv {border-bottom: 2px solid #EEEEEE;}
  ul.link{margin: 10px auto;}
  ul.link li{list-style-type: none; float: left; margin: 2px 5px;background-color:#dbeaf9;padding:5px;cursor: pointer;border-radius: 4px;}
</style>
<script type="text/javascript" charset="utf-8" src="static/calendar/calendar.php"></script>
<script type="text/javascript">
  $(document).ready(function(){
      $("#link>li").click(function()
      {
         url = $(this).attr("data-url");
         $(this).parent().siblings("input:first").val(url);
      });
      $("button#addBannerImg").click(function(){
            var num = $("#totalBannerImg").val();
            num = parseInt(num) +1;
            $("#totalBannerImg").val(num);
            var newHtml = "<div class='control-group bannerDiv' id='banner_"+num+"'><label class='control-label' for='inputTiltle'>banner（"+num+"）：<br>{if isset($imgSize)}{$imgSize}{/if}</label><div class='controls'><div class='control-group'><div><span>图片：</span><input type='file' name='img_"+num+"'></div></div></div><div class='control-group'><div class='controls'><span>跳转链接：</span><input type='text' name='link["+num+"]' placeholder='不需要跳转时请留空'> <input type='text' name='sort["+num+"]' placeholder='排序' value='0' style='width:20px'><ul id='link' class='link'>{loop $urlArr $kk $vv}<li data-url='{$vv['link']}' onclick='showLinkUrl(this)'>{$vv['name']}</li>{/loop}</ul></div></div>"
            +'<div class="control-group"style="margin:0;">'
            +    '<label class="control-label" >开始日期：</label>'
            +    '<div class="controls">'
            +        '<input type="text" name="startTime['+num+']" id="start_time_id'+num+'" value="">'
            +        "<button id=\"start_time_btn"+num+"\" type=\"button\" onclick=\"return showCalendar(\'start_time_id"+num+"', '%Y-%m-%d %H:%M:%S', '24', false, 'start_time_btn"+num+"');\" class=\"button\">选择</button>"
            +    '</div>'
            +'</div>'
            +'<div class="control-group" style="margin:0;">'
            +    '<label class="control-label" >结束日期：</label>'
            +    '<div class="controls">'
            +        '<input type="text" name="endTime['+num+']" id="end_time_id'+num+'" value="">'
            +        "<button id=\"end_time_btn"+num+"\" type=\"button\" onclick=\"return showCalendar('end_time_id"+num+"', '%Y-%m-%d %H:%M:%S', '24', false, 'end_time_btn"+num+"');\" class=\"button\">选择</button>"
            +    '</div>'
            +'</div>'
            +"<div class='controls'><button type='button' class='btn btn-danger' onclick='delBanner("+num+")'>删除Banner</button></div>"
            + "</div>";
            $("#bannerList").append(newHtml);
      });
    });
   function showLinkUrl(frm){
        url = $(frm).attr("data-url");
         $(frm).parent().siblings("input:first").val(url);
   }
  function delBanner(key)
  {
    if(confirm("确认删除？") == true)
    {
        $("#banner_"+key).remove();
        var num = $("#totalBannerImg").val();
        num = parseInt(num);
        for(var i=num; i>=0; i--){
            if($("#bannerImg_"+i).html() !== undefined){
                $("#totalBannerImg").val(i);
                return false;
            }
        }
    }
  }
</script>

<div>
  <ul class="inline">
    {loop $posi_arr $k $name}
    <li><a class="btn btn-info" href="index.php?c=admin&a=Banner&posi={$k}">{$name}</a></li>
    {/loop}
  </ul>
</div>

<form class="form-horizontal" action="index.php?c=admin&a=setBanner" method="post" enctype="multipart/form-data">
<div id="bannerList">
{loop $banners $k $v}
  <div class="control-group bannerDiv" id="banner_{$k}">
    <label class="control-label" for="inputTiltle">banner（{$k}）：<br>{if isset($imgSize)}{$imgSize}{/if}</label>
    <div class="controls">
      <div class="control-group">
        <div class="">
          <span>图片：</span>
          {if $v['img']}
            <img width="50" src="{$v['img']}" alt="banner">
          {/if}
          <input type="file" name="img_{$k}">
        </div>
      </div>
    </div>
    <div class="control-group">
        <div class="controls">
            <span>跳转链接：</span>
            <input type="text" name="link[{$k}]" placeholder="不需要跳转时请留空" value="{$v['link']}">
            <input type="text" name="sort[{$k}]" style="width: 20px;" value="{$v['sort']}"/>
            <ul id="link" class="link">
                {loop $urlArr $kk $vv}
                <li data-url="{$vv['link']}">{$vv['name']}</li>
                {/loop}
            </ul>
        </div>
    </div>
    <div class="control-group"style="margin:0;">
        <label class="control-label" >开始日期：</label>
        <div class="controls">
            <input type="text" name="startTime[{$k}]" id="start_time_id{$k}" value="{if isset($v['startTime'])}{$v['startTime']}{/if}">
            <button id="start_time_btn{$k}" type="button" onclick="return showCalendar('start_time_id{$k}', '%Y-%m-%d %H:%M:%S', '24', false, 'start_time_btn{$k}');" class="button">选择</button>
        </div>
    </div>
    <div class="control-group" style="margin:0;">
        <label class="control-label" >结束日期：</label>
        <div class="controls">
            <input type="text" name="endTime[{$k}]" id="end_time_id{$k}" value="{if isset($v['endTime'])}{$v['endTime']}{/if}">
            <button id="end_time_btn{$k}" type="button" onclick="return showCalendar('end_time_id{$k}', '%Y-%m-%d %H:%M:%S', '24', false, 'end_time_btn{$k}');" class="button">选择</button>
        </div>
    </div>
    <div class="controls"><button type="button" class="btn btn-danger" onclick="delBanner('{$k}')">删除Banner</button></div>
  </div>
{/loop}
</div>
<div class="control-group">
    <div class="controls">
        {if $banners}
        <input type="hidden" value="{eval echo count($banners)}" id="totalBannerImg" name="num">
        {else}
        <input type="hidden" value="0" id="totalBannerImg" name="num">
        {/if}
        {if isset($type)}
        <input type="hidden" name="type" value="{$type}"/>
        {/if}
        <button type="button" class="btn btn-primary" id="addBannerImg">添加Banner</button>
    </div>
</div>
<div class="control-group">
    <div class="controls">
        <input type="hidden" name="posi" value="{$posi}"/>
        <button type="submit" class="btn">提交</button>
    </div>
</div>
</form>
{template footer}
